﻿
namespace ZDS.Test

open System

open NUnit.Framework
open FsUnit

open ZDS
open TestUtility

[<TestFixture>]
type TestArrayStack() =

    [<Test>]
    member this.Sample() =
        let s = new ZArrayStack<int>(5)

        for index = 1 to 3 do
            s.Push index

        seq {
            for index = 1 to 2 do
                yield s.Pop()
        }
        |> should equal [3;2]
        s |> should equal [1]      
        s.Size |> should equal 1
        
        for index = 1 to 4 do
            s.Push <| index * index
        s |> should equal [1;1;4;9;16]

        // ----------- pushing raises exception when full
        (fun() -> s.Push 6)
        |> getErrorCode
        |> should equal ErrorCode.Full

        // ----------- pop all
        seq {
            for index = 1 to s.Capacity do
                yield s.Pop()
        }
        |> should equal  [16;9;4;1;1]
        s.Size |> should equal 0

        // ----------- poping raise exception when empty
        (fun() -> s.Pop() |> ignore)
        |> getErrorCode
        |> should equal ErrorCode.Empty



